import cv2
image=cv2.imread('hat.png',cv2.IMREAD_GRAYSCALE)
kernel=cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))
fushi=cv2.morphologyEx(image,cv2.MORPH_ERODE,kernel)
pengzhang=cv2.morphologyEx(image,cv2.MORPH_DILATE,kernel)
kaiyunsuan=cv2.morphologyEx(image,cv2.MORPH_OPEN,kernel)
biyunsuan=cv2.morphologyEx(image,cv2.MORPH_CLOSE,kernel)
gradient=cv2.morphologyEx(image,cv2.MORPH_GRADIENT,kernel)
tophat=cv2.morphologyEx(image,cv2.MORPH_TOPHAT,kernel)
blackhat=cv2.morphologyEx(image,cv2.MORPH_BLACKHAT,kernel)
cv2.imshow("Input",image)
cv2.imshow("fushi",fushi)
cv2.imshow("pengzhang",pengzhang)
cv2.imshow("kaiyunsuan",kaiyunsuan)
cv2.imshow("biyunsuan",biyunsuan)
cv2.imshow("gradient",gradient)
cv2.imshow("tophat",tophat)
cv2.imshow("blackhat",blackhat)
cv2.waitKey()
cv2.destroyAllWindows()
